﻿// CClassState.cs
// Author: Gant Briseno
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Casters.source.States.UIs;
using Casters.source.Objects;
using Casters.source.Managers;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Casters.source.Objects.Spells;
using Casters.source.AI;
#endregion

namespace Casters.source.States
{
    /// <summary>
    /// State for the Class Missions that players will embark on
    /// PvE
    /// </summary>
    public class CClassState : CBaseState
    {
        public enum Direction { Right = 0, Down, Left, Up, Max };
        public enum State { Setup = 0, Execute, Max };

        private static CClassState instance = null;
        static public CClassState GetInstance()
        {
            if (instance == null)
                instance = new CClassState();

            return instance;
        }

        // Variables
        protected CPlayer m_Player;
        protected CComputerPlayer m_Computer;
        protected CBattleUI m_UI;
        protected CTileManager m_TileManager;
        protected SpriteFont m_Font;
        protected State m_State;
        protected Vector2 m_vMoveDirection;
        protected bool m_bMove;
        protected bool m_bHasMoved;
        protected bool m_bAttack;
        protected bool m_bReplay;
        protected bool m_bSpellSelected;
        protected int m_nSelectedSpell;


        public CPlayer GetPlayer() { return m_Player; }
        public CComputerPlayer GetComputer() { return m_Computer; }
        /// <summary>
        /// Defaults the state
        /// </summary>
        public override void Initialize()
        {
            m_TileManager = CTileManager.GetInstance();

            m_UI = new CBattleUI();
            CUIManager.AddUI(m_UI);
            
            m_bMove = false;
            m_bHasMoved = false;
            m_bAttack = false;
            m_bReplay = false;
            m_bSpellSelected = false;
            m_State = State.Setup;
            m_nSelectedSpell = 0;
        }

        /// <summary>
        /// Loads all content needed for the state
        /// Registers all events
        /// </summary>
        public override void LoadContent()
        {
            // Tile Manager Initialization, this will change, currently stores the texture itself
            ContentManager loader = new ContentManager(CGame.GetInstance().Services, "Content");

            CTileManager.GetInstance().Initialize(new Vector2(10, 5), new Vector2(320, 266), new Vector2(3, 3), new Color(207, 206, 186), loader.Load<Texture2D>("NewTiles") as Texture2D);
            CTileManager.GetInstance().CreateRandomMap();

            m_Player = new CPlayer();
            m_Player.SetPlayerNumber(0);
            m_Player.m_vMovePosition = Vector2.Zero;
            m_Player.m_vCastPosition = Vector2.Zero;
            CObjectManager.AddObject(m_Player);

            m_Font = CGame.GetInstance().Content.Load<SpriteFont>("Fonts/Arial");

            CGame.GetInstance().m_Camera.m_bEnabled = true;
            CCombatManager.GetInstance().LoadContent();
            CEventSystem.RegisterEventHandler(EventID.MouseLeftClick, OnMouseLeftClick);
            CEventSystem.RegisterEventHandler(EventID.MouseRightClick, OnMouseRightClick);
            CEventSystem.RegisterEventHandler(EventID.AddScrollingText, OnAddScrollingText);
            CEventSystem.RegisterEventHandler(EventID.BattleUI_MoveClicked, OnUIMoveClicked);
            CEventSystem.RegisterEventHandler(EventID.BattleUI_CombatClicked, OnUICombatClicked);
            CEventSystem.RegisterEventHandler(EventID.BattleUI_EndTurnClicked, OnUIEndTurnClicked);
            CEventSystem.RegisterEventHandler(EventID.BattleUI_SpellClicked, OnUISpellClicked);
            CEventSystem.RegisterEventHandler(EventID.Confirm, OnConfirmClicked);
            CEventSystem.RegisterEventHandler(EventID.Back, OnCancelClicked);
            CEventSystem.RegisterEventHandler(EventID.Setup_AddMove, OnSetupAddMove);
            CEventSystem.RegisterEventHandler(EventID.EndOfCombat, OnEndOfCombat);
            CEventSystem.RegisterEventHandler(EventID.Execute_CastSpell, OnExecuteCastSpell);
            CEventSystem.RegisterEventHandler(EventID.StartOfReplay, OnReplayStart);
            CEventSystem.RegisterEventHandler(EventID.EndOfReplay, OnReplayEnd);
        }

        /// <summary>
        /// Unloads content and unregisters all events used
        /// </summary>
        public override void UnloadContent()
        {
            m_TileManager.Reset();
            CObjectManager.RemoveObject(m_Player);
            CUIManager.RemoveUI(m_UI);
            m_Font = null;

            CGame.GetInstance().m_Camera.m_bEnabled = false;
            CCombatManager.GetInstance().UnloadContent();
            CEventSystem.UnregisterEventHandler(EventID.MouseLeftClick, OnMouseLeftClick);
            CEventSystem.UnregisterEventHandler(EventID.MouseRightClick, OnMouseRightClick);
            CEventSystem.UnregisterEventHandler(EventID.AddScrollingText, OnAddScrollingText);
            CEventSystem.UnregisterEventHandler(EventID.BattleUI_MoveClicked, OnUIMoveClicked);
            CEventSystem.UnregisterEventHandler(EventID.BattleUI_CombatClicked, OnUICombatClicked);
            CEventSystem.UnregisterEventHandler(EventID.BattleUI_EndTurnClicked, OnUIEndTurnClicked);
            CEventSystem.UnregisterEventHandler(EventID.BattleUI_SpellClicked, OnUISpellClicked);
            CEventSystem.UnregisterEventHandler(EventID.Confirm, OnConfirmClicked);
            CEventSystem.UnregisterEventHandler(EventID.Back, OnCancelClicked);
            CEventSystem.UnregisterEventHandler(EventID.Setup_AddMove, OnSetupAddMove);
            CEventSystem.UnregisterEventHandler(EventID.EndOfCombat, OnEndOfCombat);
            CEventSystem.UnregisterEventHandler(EventID.Execute_CastSpell, OnExecuteCastSpell);
            CEventSystem.UnregisterEventHandler(EventID.StartOfReplay, OnReplayStart);
            CEventSystem.UnregisterEventHandler(EventID.EndOfReplay, OnReplayEnd);
        }

        /// <summary>
        /// Runs update logic for the state every frame
        /// </summary>
        /// <param name="dt">Delta Time</param>
        public override void Update(float dt)
        {
            if (m_bReplay)
                CCombatManager.GetInstance().ReplayUpdate(dt);
            else
                CCombatManager.GetInstance().Update(dt);

            if (Keyboard.GetState().IsKeyDown(Keys.H) && m_bReplay == false)
                CEventSystem.BroadcastEvent(EventID.StartOfReplay);
        }

        /// <summary>
        /// Renders the contents of the state
        /// </summary>
        public override void Draw()
        {
            m_TileManager.Render();
            CCombatManager.GetInstance().Draw(m_Font);
        }

        /// <summary>
        /// AddScrollingText: Add scrolling text to the screen
        /// </summary>
        /// <param name="eventArgs[0]">String of text to  use</param>
        /// <param name="eventArgs[1]">Vector2 position</param>
        void OnAddScrollingText(params object[] eventArgs)
        {
            if (eventArgs[0] == null || eventArgs[1] == null)
                return;

            if ((string)eventArgs[0] != "")
                CObjectManager.AddObject(new CScrollingText((string)eventArgs[0], (Vector2)eventArgs[1]));
        }

        /// <summary>
        /// MouseLeftClick: Called when the left mouse button is clicked
        /// </summary>
        /// <param name="eventArgs[0]">Vector2 mouse position</param>
        void OnMouseLeftClick(params object[] eventArgs)
        {
            Vector2 mousePos = (Vector2)eventArgs[0];

            if (m_UI.GetUIClicked())
                return;

            switch (m_State)
            {
                case State.Setup:
                    if (m_bMove)
                    {
                        Vector2 dest = CTileManager.GetInstance().ClickOnTiles(mousePos);
                        if (dest.X == -1 || dest.Y == -1)
                            break;

                        if (CTileManager.GetInstance().m_TileMap[(int)dest.X, (int)dest.Y].m_CanMoveTo)
                        {
                            if (m_Player.m_vMovePosition == Vector2.Zero)
                                m_UI.LoadReadyCheck(true, false);
                            else
                                CTileManager.GetInstance().ChangeTileColor(m_Player.m_vMovePosition, Color.DodgerBlue);

                            CTileManager.GetInstance().ChangeTileColor(dest, Color.LightCyan);
                            m_Player.m_vMovePosition = dest;
                            Vector2 dir = dest - m_Player.m_vPositionOnMap;
                            dir.Normalize();
                            m_vMoveDirection = dir;
                        }
                    }
                    else if (m_bAttack)
                    {
                        Vector2 dest = CTileManager.GetInstance().ClickOnTiles(mousePos);
                        if (dest.X == -1 || dest.Y == -1)
                            break;

                        if (CTileManager.GetInstance().m_TileMap[(int)dest.X, (int)dest.Y].m_CanAttack)
                        {
                            if (m_Player.m_vCastPosition == Vector2.Zero)
                                m_UI.LoadReadyCheck(true, false);
                            else
                                CTileManager.GetInstance().ChangeTileColor(m_Player.m_vCastPosition, Color.Red);

                            CTileManager.GetInstance().ChangeTileColor(dest, Color.PaleVioletRed);
                            m_Player.m_vCastPosition = dest;
                        }
                    }
                    break;
                case State.Execute:
                    break;
                default:
                    break;
            }
        }

        /// <summary>
        /// MouseRightClick: Called when the right mouse button is clicked
        /// </summary>
        /// <param name="eventArgs[0]">Vector2 mouse position</param>
        void OnMouseRightClick(params object[] eventArgs)
        {
            CTileManager.GetInstance().ResetTileColor();
        }

        /// <summary>
        /// BattleUI_MoveClicked: Player clicked the Move button while in battle
        /// </summary>
        /// <param name="eventArgs">None</param>
        void OnUIMoveClicked(params object[] eventArgs)
        {
            if (m_State != State.Setup || m_bMove == true || m_bHasMoved == true || m_bAttack == true || m_Player.GetTickMax())
                return;

            m_bMove = true;
            CTileManager.GetInstance().MarkTiles(m_Player.m_vPositionOnMap, 2, Color.DodgerBlue, true);
            m_UI.LoadReadyCheck(false);
        }

        /// <summary>
        /// BattleUI_CombatClicked: Player clicked the Combat button while in battle
        /// </summary>
        /// <param name="eventArgs">None</param>
        void OnUICombatClicked(params object[] eventArgs)
        {
            if (m_State != State.Setup || m_bAttack == true || m_bMove == true || m_Player.GetTickMax())
                return;

            m_bAttack = true;
            m_UI.LoadSpells(m_Player);
            m_UI.LoadReadyCheck(false);
        }

        /// <summary>
        /// BattleUI_EndTurnClicked: Player clicked the End Turn button while in battle
        /// </summary>
        /// <param name="eventArgs">None</param>
        void OnUIEndTurnClicked(params object[] eventArgs)
        {
            if (m_State != State.Setup || m_bMove == true || m_bAttack == true)
                return;

            CEventSystem.BroadcastEvent(EventID.StartOfCombat);
            m_State = State.Execute;
            m_UI.UnloadMCE();

            if(m_Player.m_vMoveDirection != Vector2.Zero)
                CEventSystem.BroadcastEvent(EventID.AddAction, m_Player, 1, 1, EventID.Setup_AddMove, m_Player.m_vMoveDirection, null);
        }

        /// <summary>
        /// BattleUI_SpellClicked: Player clicked a spell button while in battle
        /// </summary>
        /// <param name="eventArgs">None</param>
        void OnUISpellClicked(params object[] eventArgs)
        {
            m_nSelectedSpell = (int)eventArgs[0];

            if (m_bSpellSelected == true)
                CTileManager.GetInstance().ResetTileColor();

            CTileManager.GetInstance().MarkTilesLoS(m_Player.m_vPositionOnMap, CSpellManager.GetInstance().GetSpell(m_nSelectedSpell).GetRange(), Color.Red, m_Player.m_vSightDirection, true);
            m_bSpellSelected = true;
        }

        /// <summary>
        /// EndOfCombat: Combat has finished
        /// </summary>
        /// <param name="eventArgs">None</param>
        void OnEndOfCombat(params object[] eventArgs)
        {
            m_State = State.Setup;
            m_bHasMoved = false;
            m_Player.m_vMovePosition = Vector2.Zero;
            m_Player.m_vCastPosition = Vector2.Zero;
            m_UI.LoadMCE();
            m_Player.ResetTick();
        }

        /// <summary>
        /// Confirm: Confirm selection, enter, yes
        /// </summary>
        /// <param name="eventArgs">None</param>
        void OnConfirmClicked(params object[] eventArgs)
        {
            switch (m_State)
            {
                case State.Setup:
                    if (m_bMove)
                    {
                        m_Player.m_vMoveDirection = m_vMoveDirection;
                        m_Player.IncrementTick(4);
                        m_Player.m_vMovePosition = Vector2.Zero;
                        CTileManager.GetInstance().ResetTileColor();
                        CTileManager.GetInstance().ResetTileCanMove();
                        m_bMove = false;
                        m_UI.UnloadReadyCheck();
                        m_bHasMoved = true;
                    }
                    else if (m_bAttack)
                    {
                        CEventSystem.BroadcastEvent(EventID.AddAction, m_Player, m_Player.GetTick(), 1, EventID.Execute_CastSpell, m_Player.m_vCastPosition, m_nSelectedSpell);
                        m_Player.IncrementTick(CSpellManager.GetInstance().GetSpell(m_Player.GetSpell(m_nSelectedSpell)).GetCooldown());
                        m_Player.m_vCastPosition = Vector2.Zero;
                        CTileManager.GetInstance().ResetTileColor();
                        CTileManager.GetInstance().ResetTileCanAttack();
                        m_bAttack = false;
                        m_UI.UnloadReadyCheck();
                        m_UI.UnloadSpells();
                        m_bSpellSelected = false;
                    }
                    break;
                case State.Execute:
                    break;
                default:
                    break;
            }
        }

        /// <summary>
        /// Back: Back, cancel selection, no
        /// </summary>
        /// <param name="eventArgs">None</param>
        void OnCancelClicked(params object[] eventArgs)
        {
            switch (m_State)
            {
                case State.Setup:
                    if (m_bMove)
                    {
                        m_Player.m_vMovePosition = Vector2.Zero;
                        CTileManager.GetInstance().ResetTileColor();
                        CTileManager.GetInstance().ResetTileCanMove();
                        m_bMove = false;
                        m_UI.UnloadReadyCheck();
                    }
                    else if (m_bAttack)
                    {
                        m_bAttack = false;
                        m_UI.UnloadReadyCheck();
                        m_UI.UnloadSpells();
                        CTileManager.GetInstance().ResetTileColor();
                        CTileManager.GetInstance().ResetTileCanAttack();
                        m_bSpellSelected = false;
                        m_Player.m_vCastPosition = Vector2.Zero;
                    }
                    break;
                case State.Execute:
                    break;
                default:
                    break;
            }
        }

        /// <summary>
        /// Setup_AddMove: Add movement to the player queue
        /// </summary>
        /// <param name="eventArgs[0]">Position of where to move</param>
        /// <param name="eventArgs[1]">Not used</param>
        void OnSetupAddMove(params object[] eventArgs)
        {
            Vector2 mouseDir = (Vector2)eventArgs[0];
            Vector2 mousePos = m_Player.m_vPositionOnMap;
            CRenderObject obj = (CRenderObject)eventArgs[2];

            if (mouseDir != Vector2.Zero)
            {
                if (obj.GetType() == CBaseObject.TYPE.Player)
                {
                    mousePos = m_Player.m_vPositionOnMap + (mouseDir * 2f);
                    Vector2 mapSize = CTileManager.GetInstance().m_vMapSize;

                    if (mousePos.X >= mapSize.X || mousePos.X < 0f || mousePos.Y >= mapSize.Y || mousePos.Y < 0f)
                    {
                        mousePos = m_Player.m_vPositionOnMap + mouseDir;

                        if (mousePos.X >= mapSize.X || mousePos.X < 0f || mousePos.Y >= mapSize.Y || mousePos.Y < 0f)
                        {
                            mousePos = m_Player.m_vPositionOnMap;
                            CEventSystem.BroadcastEvent(EventID.Execute_ResetMove);
                        }
                    }

                    MovePlayerToTile(mousePos);
                }
                else if (obj.GetType() == CBaseObject.TYPE.Computer)
                {
                    mousePos = m_Computer.m_vPositionOnMap + (mouseDir * 2f);
                    Vector2 mapSize = CTileManager.GetInstance().m_vMapSize;

                    if (mousePos.X >= mapSize.X || mousePos.X < 0f || mousePos.Y >= mapSize.Y || mousePos.Y < 0f)
                    {
                        mousePos = m_Computer.m_vPositionOnMap + mouseDir;

                        if (mousePos.X >= mapSize.X || mousePos.X < 0f || mousePos.Y >= mapSize.Y || mousePos.Y < 0f)
                        {
                            mousePos = m_Computer.m_vPositionOnMap;
                            CEventSystem.BroadcastEvent(EventID.Execute_ResetMove);
                        }
                    }

                    MoveComputerToTile(mousePos);
                }
            }

            
        }

        /// <summary>
        /// Move the player to the tile that has been clicked
        /// </summary>
        /// <param name="mousePos">Position where the player clicked</param>
        void MovePlayerToTile(Vector2 mousePos)
        {
            if (m_Player.GetIsMoving() == true)
                return;

            CTileManager.GetInstance().ResetTileColor();

            // Get the center point of the destination tile
            // if there is no tile return
            Vector2 dest = mousePos;// CTileManager.GetInstance().ClickOnTiles(mousePos);
            if (dest.X == -1f && dest.Y == -1f)
                return;

            Vector2 pos = m_Player.m_vPositionOnMap;
            Vector2 result = dest - pos;

            // Figure out the starting direction and how far to go
            int path = 0;
            Direction direction = Direction.Max;
            if (Math.Abs(result.X) > Math.Abs(result.Y))
            {
                path = (int)(Math.Abs(result.X) - Math.Abs(result.Y));

                if (result.X > 0)
                    direction = Direction.Right;
                else
                    direction = Direction.Left;
            }
            else if (Math.Abs(result.X) < Math.Abs(result.Y))
            {
                path = (int)(Math.Abs(result.Y) - Math.Abs(result.X));

                if (result.Y > 0)
                    direction = Direction.Down;
                else
                    direction = Direction.Up;
            }
            else
            {
                path = (int)(Math.Abs(result.X) - Math.Abs(result.Y));

                if (result.X > 0)
                    direction = Direction.Right;
                else
                    direction = Direction.Left;
            }

            // Add all of the straight path movement to the queue
            for (int i = 0; i < path; ++i)
            {
                m_Player.AddToMoveQueue((int)direction);
            }

            // Figure out the direction to move next
            Direction newDir = Direction.Max;
            if (direction == Direction.Up || direction == Direction.Down)
            {
                if (result.X > 0)
                    newDir = Direction.Right;
                else
                    newDir = Direction.Left;
            }
            else
            {
                if (result.Y > 0)
                    newDir = Direction.Down;
                else
                    newDir = Direction.Up;
            }

            // Setup result so that it is a uniform Vec2
            switch (direction)
            {
                case Direction.Right:
                    result.X -= path;
                    break;
                case Direction.Left:
                    result.X += path;
                    break;
                case Direction.Down:
                    result.Y -= path;
                    break;
                case Direction.Up:
                    result.Y += path;
                    break;
            }

            // At this point you need to move in a diagonal to get to the destination
            // Alternate adding directions until you've reached your destination
            bool bNewDir = true;
            while (result != Vector2.Zero)
            {
                if (bNewDir)
                {
                    m_Player.AddToMoveQueue((int)newDir);
                    bNewDir = false;

                    switch (newDir)
                    {
                        case Direction.Right:
                            result.X -= 1f;
                            break;
                        case Direction.Left:
                            result.X += 1f;
                            break;
                        case Direction.Down:
                            result.Y -= 1f;
                            break;
                        case Direction.Up:
                            result.Y += 1f;
                            break;
                    }
                }
                else
                {
                    m_Player.AddToMoveQueue((int)direction);
                    bNewDir = true;

                    switch (direction)
                    {
                        case Direction.Right:
                            result.X -= 1f;
                            break;
                        case Direction.Left:
                            result.X += 1f;
                            break;
                        case Direction.Down:
                            result.Y -= 1f;
                            break;
                        case Direction.Up:
                            result.Y += 1f;
                            break;
                    }
                }
            }
        }

        /// <summary>
        /// Move the computer to the tile that has been selected
        /// </summary>
        /// <param name="mousePos">Position where the computer is moving to</param>
        void MoveComputerToTile(Vector2 mousePos)
        {
            if (m_Computer.GetIsMoving() == true)
                return;

            CTileManager.GetInstance().ResetTileColor();

            // Get the center point of the destination tile
            // if there is no tile return
            Vector2 dest = mousePos;// CTileManager.GetInstance().ClickOnTiles(mousePos);
            if (dest.X == -1f && dest.Y == -1f)
                return;

            Vector2 pos = m_Computer.m_vPositionOnMap;
            Vector2 result = dest - pos;

            // Figure out the starting direction and how far to go
            int path = 0;
            Direction direction = Direction.Max;
            if (Math.Abs(result.X) > Math.Abs(result.Y))
            {
                path = (int)(Math.Abs(result.X) - Math.Abs(result.Y));

                if (result.X > 0)
                    direction = Direction.Right;
                else
                    direction = Direction.Left;
            }
            else if (Math.Abs(result.X) < Math.Abs(result.Y))
            {
                path = (int)(Math.Abs(result.Y) - Math.Abs(result.X));

                if (result.Y > 0)
                    direction = Direction.Down;
                else
                    direction = Direction.Up;
            }
            else
            {
                path = (int)(Math.Abs(result.X) - Math.Abs(result.Y));

                if (result.X > 0)
                    direction = Direction.Right;
                else
                    direction = Direction.Left;
            }

            // Add all of the straight path movement to the queue
            for (int i = 0; i < path; ++i)
            {
                m_Computer.AddToMoveQueue((int)direction);
            }

            // Figure out the direction to move next
            Direction newDir = Direction.Max;
            if (direction == Direction.Up || direction == Direction.Down)
            {
                if (result.X > 0)
                    newDir = Direction.Right;
                else
                    newDir = Direction.Left;
            }
            else
            {
                if (result.Y > 0)
                    newDir = Direction.Down;
                else
                    newDir = Direction.Up;
            }

            // Setup result so that it is a uniform Vec2
            switch (direction)
            {
                case Direction.Right:
                    result.X -= path;
                    break;
                case Direction.Left:
                    result.X += path;
                    break;
                case Direction.Down:
                    result.Y -= path;
                    break;
                case Direction.Up:
                    result.Y += path;
                    break;
            }

            // At this point you need to move in a diagonal to get to the destination
            // Alternate adding directions until you've reached your destination
            bool bNewDir = true;
            while (result != Vector2.Zero)
            {
                if (bNewDir)
                {
                    m_Computer.AddToMoveQueue((int)newDir);
                    bNewDir = false;

                    switch (newDir)
                    {
                        case Direction.Right:
                            result.X -= 1f;
                            break;
                        case Direction.Left:
                            result.X += 1f;
                            break;
                        case Direction.Down:
                            result.Y -= 1f;
                            break;
                        case Direction.Up:
                            result.Y += 1f;
                            break;
                    }
                }
                else
                {
                    m_Computer.AddToMoveQueue((int)direction);
                    bNewDir = true;

                    switch (direction)
                    {
                        case Direction.Right:
                            result.X -= 1f;
                            break;
                        case Direction.Left:
                            result.X += 1f;
                            break;
                        case Direction.Down:
                            result.Y -= 1f;
                            break;
                        case Direction.Up:
                            result.Y += 1f;
                            break;
                    }
                }
            }
        }

        /// <summary>
        /// Execute_CastSpell: Casts a spell during execute state
        /// </summary>
        /// <param name="eventArgs[0]">The target</param>
        /// <param name="eventArgs[1]">The spell to use</param>
        /// <param name="eventArgs[2]">The owner of the spell</param>
        public void OnExecuteCastSpell(params object[] eventArgs)
        {
            Vector2 target = (Vector2)eventArgs[0];
            int spellSlot = (int)eventArgs[1];
            CPlayer owner = (CPlayer)eventArgs[2];

            target = CTileManager.GetInstance().GetTileCenterpointPosition(target);
            string temp = CSpellManager.GetInstance().GetSpell(owner.GetSpell(spellSlot)).GetName();
            CEventSystem.BroadcastEvent(EventID.AddScrollingText, temp, target);
            // Will create the CSpellObject here
            CObjectManager.AddObject(new CSpellObject(CSpellManager.GetInstance().GetSpell(owner.GetSpell(spellSlot)), owner.m_vPosition, target, 100f));
        }

        /// <summary>
        /// Called when the battle is over and it's time to show how the battle went
        /// </summary>
        /// <param name="eventArgs">None</param>
        public void OnReplayStart(params object[] eventArgs)
        {
            CEventSystem.BroadcastEvent(EventID.StartOfCombat);
            m_Player.ResetPlayer();
            m_bReplay = true;
        }

        /// <summary>
        /// Called when the replay is over with
        /// </summary>
        /// <param name="eventArgs">None</param>
        public void OnReplayEnd(params object[] eventArgs)
        {
        }

        /// <summary>
        /// Resets the player's move direction
        /// </summary>
        /// <param name="eventArgs">None</param>
        public void OnResetMove(params object[] eventArgs)
        {
            m_Player.m_vMoveDirection = Vector2.Zero;
        }
    }
}
